<?php

/**
 * This is the model class for table "mst_perusahaan_asuransi".
 *
 * The followings are the available columns in table 'mst_perusahaan_asuransi':
 * @property integer $id
 * @property string $no_insurance
 * @property string $name
 * @property string $address
 * @property integer $city_id
 * @property integer $province_id
 * @property string $zip_code
 * @property string $phone
 * @property string $fax
 * @property integer $createdby
 * @property string $createdtime
 * @property integer $updatedby
 * @property string $updatedtime
 * @property integer $jenis_asuransi_id
 */
class MstPerusahaanAsuransi extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'mst_perusahaan_asuransi';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, address, city_id, province_id', 'required'),
			array('city_id, province_id, createdby, updatedby, jenis_asuransi_id', 'numerical', 'integerOnly'=>true),
			array('no_insurance, name, address', 'length', 'max'=>50),
			array('zip_code', 'length', 'max'=>10),
			array('phone, fax', 'length', 'max'=>20),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, no_insurance, name, address, city_id, province_id, zip_code, phone, fax, createdby, createdtime, updatedby, updatedtime, jenis_asuransi_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'no_insurance' => 'No',
			'name' => 'Nama Perusahaan',
			'address' => 'Alamat',
			'city_id' => 'Kota',
			'province_id' => 'Propinsi',
			'zip_code' => 'Kode Pos',
			'phone' => 'Telepon',
			'fax' => 'Fax',
			'createdby' => 'Createdby',
			'createdtime' => 'Createdtime',
			'updatedby' => 'Updatedby',
			'updatedtime' => 'Updatedtime',
			'jenis_asuransi_id' => 'Jenis Asuransi',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('lower(no_insurance)',strtolower($this->no_insurance),true);
		$criteria->compare('lower(name)',strtolower($this->name),true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('city_id',$this->city_id);
		$criteria->compare('province_id',$this->province_id);
		$criteria->compare('zip_code',$this->zip_code,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('fax',$this->fax,true);
		$criteria->compare('createdby',$this->createdby);
		$criteria->compare('createdtime',$this->createdtime,true);
		$criteria->compare('updatedby',$this->updatedby);
		$criteria->compare('updatedtime',$this->updatedtime,true);
		$criteria->compare('jenis_asuransi_id',$this->jenis_asuransi_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return MstPerusahaanAsuransi the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
